package com.blueocean_health.care.management.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.blueocean_health.care.management.domain.base.NurseGroup;
import com.blueocean_health.care.management.domain.base.NurseGroupRelation;
import com.blueocean_health.care.management.domain.dto.PullDownDto;
import com.blueocean_health.care.management.domain.dto.SelectNurseGroupDto;
import com.blueocean_health.care.management.domain.groupvo.SelectNurseGroupVo;
import com.blueocean_health.care.management.domain.worktablevo.NurseWorker;
import com.blueocean_health.care.management.util.MyMapper;

public interface NurseGroupMapper extends MyMapper<NurseGroup> {
	
	/**
	 * wuyanli
	 * 小组下拉列表  2018年5月16日17:54:00
	 * @param hosptialId
	 * @return
	 */
	List<PullDownDto> getGroupPull(String hosptialId);

    @Select("SELECT * FROM nurse_group WHERE group_name =#{groupName} AND deflag = 0 and hospital_id =#{hospitalId}")
    public NurseGroup getNurseGroupByName(@Param("groupName") String groupName,@Param("hospitalId") String hospitalId);

    @Update("UPDATE nurse_group SET deflag =#{deflag} ,update_time = NOW() WHERE group_id =#{groupId} ")
	public int updateNurseGroupDeflagByGroupId(@Param("groupId") Integer groupId,@Param("deflag") String deflag);

    //有无保底薪资 默认为无  1：有 0：无
    @Insert("INSERT INTO nurse_group " +
			"(group_name,proportions,deflag,create_time,update_time,hospital_id,group_name_py,nurse_fee_type,have_payroll) " +
			"VALUES " +
			"(#{groupName},#{proportions},#{deflag},#{createTime},#{updateTime},#{hospitalId},#{groupNamePy},#{nurseFeeType},#{havePayroll})")
	@Options(useGeneratedKeys = true, keyProperty = "groupId",keyColumn = "group_id")
	public int add(NurseGroup nurseGroup);
    
    @Select("SELECT COUNT(*) FROM nurse_group_relation_v A "
    		+ "INNER JOIN nurse_group B ON A.group_id=B.group_id AND B.deflag=0 "
    		+ "WHERE A.nurse_id=#{workerId}")
    public int getWorkerIdGroupNumber(@Param("workerId")String workerId);

    @Select("SELECT " +
			"B.`nurse_id` " +
			"FROM " +
			"nurse_group A " +
			"LEFT JOIN nurse_group_relation_v B " +
			"ON A.group_id = B.group_id " +
			"WHERE A.deflag = 0 " +
			"AND A.group_id =#{groupId} " +
			"AND B.deflag = 0 ")
    public List<String> getAllWorkIdsByGroupId(@Param("groupId")Integer groupId);

	/**
	 * 查询小组详细信息
	 * @param selectNurseGroupDto
	 * @param hospitalId 当前登录人所在医院
	 * @return
	 */
	SelectNurseGroupVo query(@Param("selectNurseGroupDto")SelectNurseGroupDto selectNurseGroupDto, @Param("hospitalId")String hospitalId);

	/**
	 * 查询小组列表
	 * @param selectNurseGroupDto
	 * @param hospitalId 当前登录人所在医院
	 * @return
	 */
	List<SelectNurseGroupVo> list(@Param("selectNurseGroupDto")SelectNurseGroupDto selectNurseGroupDto, @Param("hospitalId")String hospitalId);

	/**
	 * 新建类型为多对多订单，模糊查询小组
	 * @param selectNurseGroupDto
	 * @param hospitalId
	 * @return
	 */
	List<Map<String, String>> selectGroup(@Param("selectNurseGroupDto")SelectNurseGroupDto selectNurseGroupDto, @Param("hospitalId")String hospitalId);

	/**
	 * 选择成员
	 * @param selectNurseGroupDto
	 * @param hospitalId
	 * @return
	 */
	List<Map<String, String>> selectNurse(@Param("selectNurseGroupDto")SelectNurseGroupDto selectNurseGroupDto, @Param("hospitalId")String hospitalId);

	/**
	 * 查询护工编号对应的组员信息
	 * @param workerId
	 * @return
	 */
	public NurseGroupRelation selectByWorkerId(@Param("workerId")String workerId);
	/**
	 * 根据医院id,获取用户组的名称
	 *@author lcf
	 *@date 2018年8月8日
	 *@version 1.0
	 */
	public List<NurseWorker> getWokerGroupNameByhospitalId(@Param("hospitalId")String hospitalId);
	/**
	 * 根据医院id,获取用户的名称
	 *@author lcf
	 *@date 2018年8月8日
	 *@version 1.0
	 */
	public List<NurseWorker> getWokerNameByhospitalId(@Param("hospitalId")String hospitalId);
}